R graphs
Explore and analize data visually
Dr. Peng Zhao (✉ peng.zhao@xjtlu.edu.cn)
Department of Health and Environmental Sciences
Xi’an Jiaotong-Liverpool University
1 Prerequisites
2 Objectives
Don’t be too ambitious.
- Know what graphs R could produce (R Graph Gallery).
- Know four popular R systems for graphing, including basic packages, ggplot2, plotly, and rgl.
- Reproduce the graphs shown in this workshop by yourself.
3 What R can plot
3.1 Traditional
3.2 Interactive
3.3 Animated
3.4 Geographical
3.5 Amazing
3.6 Ubiquitous
4 Graph components
Graph area
- Plotting area
- Axes
- Legends
Figure number + caption (not required in this module)
5 Packages
5.1 Base R
| Cat. | Function | Usage |
|---|---|---|
| High level | plot() |
x-y scatter plot. Relationship between two variables. |
pairs() |
||
symbols() |
||
hist() |
||
curve() |
||
barplot() |
||
boxplot() |
||
coplot() |
||
dotchart() |
||
stripchart() |
||
image() |
||
contour() |
||
| Low level | lines() |
|
points() |
||
abline() |
||
axis() |
||
legend() |
||
text() |
||
mtext() |
||
layout() |
5.2 ggplot2
ggplot() + # mandatory: data mapping
geom_xxx() + # mandatory: geometry shape
coordinate_xxx() +
theme() +
facet_xxx() +
...| Function | Usage |
|---|---|
geom_point() |
x-y scatter plot. Relationship between two variables. |
geom_line() |
|
geom_bar() |
|
geom_histogram() |
|
geom_freqpoly() |
|
geom_density() |
|
geom_boxplot() |
|
geom_bin2d() |
|
geom_density2d() |
|
geom_contour() |
|
geom_abline() |
|
geom_text() |
|
geom_errorbar() |
|
geom_polygon() |
|
geom_rect() |
|
geom_smooth() |
6 Graphical User Interface
library(GrapheR)
run.GrapheR()library(Rcmdr)ggplotgui::ggplot_shiny()library(Deducer)
JGR()7 Further readings
- R Tutorials on TechVidvan:
- R for Data Science
- ggplot2 gallery
- More books:
- Modern Statistical Graphs (现代统计图形)
- ggplot2: Elegant Graphics for Data Analysis
- Data visualisation in R for Data Science
- Graphing Data with R